blob: d0776dbb81ceb3d6d1ec2f130bc09f5c6600a186 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import { getPost, getPosts } from '$lib/utils/posts';
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';
export const prerender = true;
// Generate all post routes at build time
export function entries() {
const posts = getPosts();
return posts.map((post) => ({ slug: post.slug }));
}
export const load: PageLoad = async ({ params }) => {
const slug = params.slug;
const post = getPost(slug);
if (!post) {
error(404, `Post not found: ${slug}`);
}
return {
content: post.default,
metadata: post.metadata,
slug
};
};
|